import { IPSAppDataEntity } from '../../app/dataentity/ipsapp-data-entity';
import { IPSAppDEField } from '../../app/dataentity/ipsapp-defield';
import { IPSModelObject } from '../../ipsmodel-object';
import { PSModelServiceProxyImpl } from '../../psmodel-service-proxy-impl';

/**
 * 全局默认通用代理
 *
 * @author chitanda
 * @date 2021-06-08 20:06:55
 * @export
 * @class PSAppDEFieldServiceProxy
 * @extends {PSModelServiceProxyImpl}
 */
export class PSAppDEFieldServiceProxy extends PSModelServiceProxyImpl {
  getPSModel4(
    relatedPSModelObject: IPSModelObject,
    cls: string,
    objNode: any,
    strTag: string,
  ): IPSModelObject {
    switch (strTag) {
      case 'getComputePSAppDEFLogic':
      case 'getDefaultValuePSAppDEFLogic':
      case 'getOnChangePSAppDEFLogic':
        return this.getPSDELogic(
          relatedPSModelObject as IPSAppDEField,
          objNode,
        );
    }
    return this.getRealPSModelService().getPSModel4(
      relatedPSModelObject,
      cls,
      objNode,
      strTag,
    );
  }

  getPSDELogic(r: IPSAppDEField, obj: any): any {
    if (obj.modelref) {
      const p = this.getParentPSModelObject(
        r,
        'app.dataentity.IPSAppDataEntity',
      ) as IPSAppDataEntity;
      if (p) {
        return p.findPSAppDELogic(obj);
      }
    }
    return null;
  }
}
